home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: newsgate.melpar.esys.com!melpar!beuttel
- From: beuttel@pepman.mfg.melpar.esys.com (Stephen Beuttel - UC Test)
- Subject: OVLD >> op to input 2 doubles to obj?
- Sender: news@melpar.esys.com (Melpar News Administrator)
- Organization: E-Systems, Melpar Division
- Date: Fri, 15 Mar 1996 19:33:55 GMT
- Message-ID: <beuttel.826918435@melpar>
- Distribution: comp.lang.c++
-
-
- Hi,
-
- I'm doing an assignment for my C++ class that, in part, requires me to
- modify a class Complex ( as in 'complex numbers' ) to include a friend
- function that overloads the stream extraction operator so that when passed
- a right parameter of the object( type Complex ) it will input the two
- float members 'real' & 'imaginary'.
-
- Neither my text ( _C++ How To Program_ ) or Stroustrup's book show a way
- to do this. Between them I see only how to overload the operator to do three
- things: 1) input integer members, 2) char/array members, & 3) failbits.
-
- Would someone in this group tell me how to do the float thing? Or where
- a resource might be? Do you think I'm just going to have to create char-array
- members and then do conversion?
- ( Seems rather lame for such a touted language ). <8-O
-
- Below's an idea of the code:
-
- class Complex
- {
- public:
- Complex(double = 0.0, double = 0.0);
- :
- :
- friend istream &operator>>(istream &, Complex &);
- :
- private:
- double real;
- double imaginary;
- };
-
- :
- :
- istream &operator>>(istream &strm, Complex &in_obj)
- {
- :
- ??????STUFF
- :
- return strm;
- }
- :
- :
- int main( void )
- {
- Complex a, ... ;
- :
- :
- cin >> a;
- :
- return 0;
- }
-
- THANKS:
-
- - Steve -
-
-